<?php

namespace App\Http\Controllers;

use App\Http\Requests\StoreNavbarRequest;
use App\Http\Requests\UpdateNavbarRequest;
use App\Models\Navbar;
use Illuminate\Http\Request;

class NavbarController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return Navbar::all();
    }


    /**
     * Store a newly created resource in storage.
     *
     * @param  \App\Http\Requests\StoreNavbarRequest  $request
     * @return \Illuminate\Http\Response
     */
    public function store(StoreNavbarRequest $request)
    {
        $navbar = Navbar::create($request->all());

        return $this->successful($navbar);
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\Navbar  $navbar
     * @return \Illuminate\Http\Response
     */
    public function show(Navbar $navbar)
    {
        return $this->successful($navbar);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \App\Http\Requests\UpdateNavbarRequest  $request
     * @param  \App\Models\Navbar  $navbar
     * @return \Illuminate\Http\Response
     */
    public function update(UpdateNavbarRequest $request, Navbar $navbar)
    {
        $navbar->update($request->all());
        return $this->successful($navbar);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Navbar  $navbar
     * @return \Illuminate\Http\Response
     */
    public function destroy(Navbar $navbar)
    {
        $navbar->delete();
        return $this->successful();
    }

    public function deleteMany(Request $request)
    {
        $ids = $request->input('ids');
        if (empty($ids)) return $this->fail('请选择要删除的记录');

        Navbar::destroy($ids);
        return $this->successful();
    }
}
